import request from '@/utils/request'

export interface MenuTreeItem {
  id: number
  name: string
  path?: string
  icon?: string
  type: string
  visible: boolean
  sort: number
  parentId?: number
  children?: MenuTreeItem[]
}

export const permissionApi = {
  /**
   * 获取当前用户的菜单树
   */
  getMenuTree: () => 
    request.get<MenuTreeItem[]>('/permissions/menu-tree'),
  
  /**
   * 获取当前用户的权限列表
   */
  getUserPermissions: () => 
    request.get<string[]>('/permissions/user-permissions'),
  
  /**
   * 检查用户是否有指定权限
   */
  hasPermission: (permission: string) => 
    request.get<boolean>(`/permissions/check/${encodeURIComponent(permission)}`),

  /**
   * 获取所有权限树
   */
  getPermissionTree: () =>
    request.get('/permissions/tree'),

  /**
   * 创建权限
   */
  createPermission: (permission: any) =>
    request.post('/permissions', permission),

  /**
   * 更新权限
   */
  updatePermission: (id: number, permission: any) =>
    request.put(`/permissions/${id}`, permission),

  /**
   * 删除权限
   */
  deletePermission: (id: number) =>
    request.delete(`/permissions/${id}`)
}


